<?php

/***

LZRoster: A roster for World of Warcraft.
Copyright (C) 2007  Emmanuel Cron

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

***/

/**
 * Class used to represent a single roster character.
 * 
 * @author Emmanuel Cron
 *
 */
class Character
{	
	/** Id. */
	private $id;
	/** Name. */
	private $name;
	/** Revision of the profiler used to gather this data. */
	private $revision;
	/** Locale used when data was gathered. */
	private $locale;
	/** Faction of the character in English ('Alliance', 'Horde'). */
	private $faction_en;
	/** Race of the character in English ('NightElf', 'Human', ...). */
	private $race_en;
	/** Class of the character in English capitals ('HUNTER', 'WARRIOR', ...). */
	private $class_en;
	/** Sex of the character (2 = male, 3 = female). */
	private $sex_id;
	/** Level of the character. */
	private $level;
	/** Experience of the character. */
	private $current_experience;
	/** Experience needed for next level. */
	private $max_experience;
	/** "Blue" experience. */
	private $rested_experience;
	/** Guild title ('Alt', 'Rookie', ...). */
	private $guild_title;
	/** Guild rank (1, 2, ...). */
	private $guild_rank;
	/** Time played in seconds. */
	private $time_played;
	/** Time played at this level in seconds. */
	private $time_level_played;
	/** Timestamp of last update time. */
	private $timestamp_update;
	
	/** List of character's dungeons access. */
	private $access = array();
	/** List of character's known professions (ex: "Cooking,Leatherworking,First Aid"). */
	private $professions = array();
	/** List of character's profession specializations. */
	private $specializations = array();
	
	/**
	 * Creates a new character based on the given
	 * array.
	 * 
	 * @param $t an array containing the data needed
	 * 		to create a new character
	 */
	function Character($t)
	{
		$this->id = $t['character_id'];
		$this->name = $t['Name'];
		$this->revision = $t['Revision'];
		$this->locale = $t['Locale'];
		$this->faction_en = $t['FactionEn'];
		$this->race_en = $t['RaceEn'];
		$this->class_en = $t['ClassEn'];
		$this->sex_id = $t['SexId'];
		$this->level = $t['Level'];
		$this->current_experience = $t['CurrentExperience'];
		$this->max_experience = $t['MaxExperience'];
		$this->rested_experience = $t['RestedExperience'];
		$this->guild_title = $t['GuildTitle'];
		$this->guild_rank = $t['GuildRank'];
		$this->time_played = $t['TimePlayed'];
		$this->time_level_played = $t['TimeLevelPlayed'];
		$this->timestamp_update = $t['timestampUpdate'];
		
		if ( array_key_exists('Dungeon', $t) and $t['Dungeon'] != null )
		{
			array_push($this->access, $t['Dungeon']);
		}
		
		if ( array_key_exists('Professions', $t) and $t['Professions'] != null )
		{
			// Explode <profession1>,<profession2>,<...> in an array
			$this->professions = explode(",", $t['Professions']);
		}
		
		if ( array_key_exists('Specializations', $t) and $t['Specializations'] != null )
		{
			// Explode <specialization1>,<specialization2>,<...> in an array
			$this->specializations = explode(",", $t['Specializations']);
		}
	}
	
	function GetId()
	{
		return $this->id;
	}
	
	function GetName()
	{
		return $this->name;
	}
	
	/**
	 * Returns the race in English of
	 * this character
	 * 
	 * @return string the race in English,
	 * 		such as 'NightElf', 'Human'
	 */
	function GetRace()
	{
		return $this->race_en;
	}
	
	/**
	 * Returns the class in English
	 * capitals of this character.
	 * 
	 * @return string the class of this character,
	 * 		such as 'HUNTER', 'WARRIOR'
	 */
	function GetClass()
	{
		return $this->class_en;
	}
	
	/**
	 * Gets the sex of this character.
	 * 
	 * @return 2 for male, 3 for female
	 */
	function GetSexId()
	{
		return $this->sex_id;
	}
	
	/**
	 * Adds the given dungeon to the
	 * access available to this character.
	 * 
	 * @param $dungeon a dungeon id, such as "arcatraz",
	 * 		"caverns_of_time", ...
	 */
	function AddDungeon($dungeon)
	{
		array_push($this->access, $dungeon);
	}
	
	/**
	 * Gets the professions known by this
	 * character.
	 * 
	 * @return array a list of profession
	 * 		ids
	 */
	function GetProfessions()
	{
		return $this->professions;
	}
	
	/**
	 * Gets the specializations available to
	 * this character.
	 * 
	 * @return array a list of specialization
	 * 		ids
	 */
	function GetSpecializations()
	{
		return $this->specializations;
	}
	
	function GetGuildRank()
	{
		return $this->guild_rank;
	}
	
	function GetGuildTitle()
	{
		return $this->guild_title;
	}
	
	function GetLevel()
	{
		return $this->level;
	}
	
	function GetRevision()
	{
		return $this->revision;
	}
	
	function GetLastUpdate()
	{
		return $this->timestamp_update;
	}
	
	function GetTimePlayed()
	{
		return $this->time_played;
	}
	
	function GetTimeLevelPlayed()
	{
		return $this->time_level_played;
	}
	
	function GetCurrentExperience()
	{
		return $this->current_experience;
	}
	
	function GetMaxExperience()
	{
		return $this->max_experience;
	}
	
	function GetRestedExperience()
	{
		return $this->rested_experience;
	}
	
	/**
	 * Gets the access available to this
	 * character.
	 * 
	 * @return array a list of dungeon
	 * 		access ids
	 */
	function GetAccess()
	{
		return $this->access;
	}
	
	/**
	 * Checks if this character has access to the
	 * given dungeon.
	 * 
	 * @param $dungeon a dungeon id, such as "arcatraz",
	 * 		"caverns_of_time", ...
	 * @return boolean true if character has access to
	 * 		the dungeon, false otherwise
	 */
	function HasDungeonAccess($dungeon)
	{
		if ( in_array($dungeon, $this->access) )
		{
			return true;
		}
		else
		{
			return false;	
		}
	}
}

?>